<html ng-app="baseDirective">
<head>
<title>节点消息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../build/common/base.css" rel="stylesheet">

<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/ngEdit.js"></script>
<script type="text/javascript" src="../../build/common/uedtor.js"></script>

<script type="text/javascript">
	var app = angular.module('baseDirective');
	app.controller("ctrl", [ '$scope', 'baseService','ArrayToolService',  function(scope, baseService,ArrayToolService) {
		scope.ArrayTool = ArrayToolService;
		var defId = $.getParam("defId");
		if(!window.passData) window.passData={};
		scope.carbonCopy = window.passData.carbonCopy;
		scope.nodeList = window.passData.nodeList;
		if(!scope.carbonCopy || !scope.carbonCopy.desc){
			//初始化
			scope.carbonCopy = {
					msgType:"email",
					htmlTemplate:"您好，请有新的流程抄送：${bpmInstance.subject} ！",
					textTemplate:"您好，请有新的流程抄送：${bpmInstance.subject} ！",
					userRules: [],
					formType : "instance"
			};
		}

		scope.addNodeUserCondition = function(i){

			var userCondition = {calcs:[],rule:""};
			if (i != undefined) {
				userCondition = angular.copy(scope.carbonCopy.userRules[i]); 
			}
			var passData = {nodeList:scope.nodeList,userCondition:userCondition};

			var url = '/bpm/nodeDef/userConditionDialog.html?defId=' + defId ;

			var dialogConf = {
				passData :passData ,width : 1000, height : 600,topOpen:true,btnAlign: 'c',title:"人员条件配置",
				url:url,
				ok: function(index,innerWindow){
					var data = innerWindow.getData();
					if (!data) return;

					scope.$apply(function() {
						scope.carbonCopy.userRules = scope.carbonCopy.userRules || [];
						if (i != undefined) {
							scope.carbonCopy.userRules[i] = data;
						} else {
							scope.carbonCopy.userRules.push(data);
						}
					});
					top.layer.close(index);
				}
			};
			jQuery.Dialog.open(dialogConf);
		}
		
		scope.getBoStr = function(node){
			var parentNode = node.getParentNode();
			if( !parentNode)return;
			
			// 主表字段
			if(node.nodeType == 'column' && parentNode.parentId=="0"){
				return "${"+parentNode.alias+".get('"+node.key+"')}";
			}
			// 子表
			if(node.nodeType == 'table' && parentNode.parentId=="0"){
				return " <#list ${"+parentNode.alias+".getChildren('"+node.key+"')} as sub> ${sub.getxxx} </#list>  参考数据结构 List<IBusinessData> ";
			}
			// 子表的字段
			if(node.nodeType == 'column' && parentNode.getParentNode().parentId=="0"){
				return " <#list ${"+parentNode.alias+".getChildren('"+node.key+"')} as sub> ${sub.get('"+node.key+"')} </#list> 参考数据结构 List<IBusinessData>";
			}
			
		}
		scope.setVariable = function (event, treeId, node) {
			var keyStr = node.name;
			// 流程变量
			if (node.nodeType == 'var'){
				keyStr = "${variableScope.getVariable('"+node.name+"')}";
			}// 业务对象取值
			else {
				 keyStr = scope.getBoStr(node);
			}
			
			if(!keyStr)return;
			
			varTree.hideMenu();
			scope.carbonCopy.htmlTemplate = scope.carbonCopy.htmlTemplate + keyStr;
			!scope.$parent.$$phase && scope.$parent.$digest();
		}
		
		scope.initTree = function(){
			varTree = new ZtreeCreator('varTree', __ctx+"/bpm/processDef/variablesTree").setDataKey({
				name : 'name'
			}).setCallback({
				onClick : scope.setVariable
			}).makeCombTree("tempTree").initZtree({ defId : defId, includeBpmConstants : true}, 2);
			
			$(".varTree").bind("click", varTree.showMenu);
		}
		scope.initTree();
	
	} ]);

	
	function getData(){
		if (!AngularUtil.getScope().form.$valid){
			$.Dialog.warning("表单校验未通过！");
			return false;
		}
		return AngularUtil.getScope().carbonCopy;
	}
</script>
</head>
<body ng-controller="ctrl">
<form name="form">
		<table class="form-table">
			<tr>
				<th>抄送描述<span class="fa fa-question-circle text-info" ab-tip title="该抄送的描述，也是抄送通知的标题"></span> </th>
				<td><input type="text" ng-model="carbonCopy.desc" class="form-control" ab-validate="{required:true,maxlength:220}"/></td>
			</tr>
			<tr>
				<th>抄送任务节点</th>
				<td>
					<select ng-model="carbonCopy.nodeId" ng-disable="disable" class="form-control" ab-validate="{required:true}"
					ng-options="node.nodeId as node.nodeName for node in nodeList" >
						<option value="">请选择</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>抄送时机:</th>
				<td>
					<select ng-model="carbonCopy.event" ng-disable="disable" class="form-control" ab-validate="{required:true}" >
						<option value="postTaskCreate">任务创建时</option>
						<option value="taskComplete">任务完成时</option>
						<option value="endEvent">流程结束时</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>抄送表单</th>
				<td>
					<span ab-boolean="task/instance" text="任务节点表单/全局实例表单" ng-model="carbonCopy.formType" ab-tip title="若选择任务节点表单，则使用抄送节点时的任务表单，否则流程实例表单"></span>
				</td>
			</tr>
			<tr>
				<th>抄送人:</th>
				<td>
					<ul class="list-group" style="width: 500px">
						<li class="list-group-item" ng-repeat="userRule in carbonCopy.userRules">
							<span>{{userRule.description}}</span>
							<div class="pull-right">
								<a href="javascript:javaScript:void(0)" ng-click="ArrayTool.up($index,carbonCopy.userRules)" class="fa fa-arrow-up  btn btn-sm btn-default"></a>
								<a href="javascript:javaScript:void(0)" ng-click="ArrayTool.down($index,carbonCopy.userRules)" class="fa fa-arrow-down btn btn-sm btn-default"></a>
								<a ng-click="addNodeUserCondition($index)" class="fa fa-edit btn btn-primary btn-sm"></a>
								<a href="javascript:javaScript:void(0)" ng-click="ArrayTool.del($index,carbonCopy.userRules)" class="fa fa-trash btn btn-sm btn-danger"></a>
							</div>
						</li>
					</ul>
					<button class="btn btn-primary btn-sm fa fa-user-o" ng-click="addNodeUserCondition()">选择</button>
				</td>
			</tr>
			<tr>
				<th>抄送提醒消息类型: <span class="required">*</span></th>
				<td  ng-model="msgList" ab-load="sys/tools/getInterFaceImpls?classPath=com.dstz.sys.simplemq.handler.msg.AbsNotifyMessageHandler" simple-data="true" > 
					<label ng-repeat="msg in msgList" ><input type="checkbox" ab-checkbox ng-model="carbonCopy.msgType" value="{{msg.type}}" ab-validate="{required:true}"/>{{msg.title}}</label>
				</td>
			</tr>
			<tr>
				<th>富文本模板: <span class="required">*</span></th>
				<td>
				<div class="form-inline">
				<a class="varTree btn btn-primary">流程变量</a>
  				<div id="tempTree"></div>
				</div>
  				<textarea type="text" ab-editor ng-model="carbonCopy.htmlTemplate" style="width: 600px;height: 300px" /></textarea></td>
			</tr>
			<tr>
				<th>普通文本模板: <span class="required">*</span></th>
				<td> <textarea rows="3"  class="form-control" ng-model="carbonCopy.textTemplate" style="width: 600px;"></textarea></td>
			</tr>
		</table>
	</form>
</body>
</html>
